﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;
using Yule8xCommon.Typelib;
using Yule8xModel;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Dimond
{
    public partial class History : System.Web.UI.Page
    {
        WxUserInfoResult wxUser;
        protected System.Data.DataTable dtList;
        protected int total_count,user_id;
        protected void Page_Load(object sender, EventArgs e)
        {
            user_id = RequestUtil.GetInteger("user_id");
            if (RuntimeDataUtil.CheckDebugModel() && user_id > 0)
            {
                wxUser = UserModels.GetWxUserInfo(user_id);
                if (null == wxUser)
                {
                    ResponseUtil.WriteEnd("user_id无效!");
                }
            }
            else
            {
                wxUser = LoginPageBase.GetLoginInfo();
                if (null == wxUser)
                {
                    Response.Redirect(WechatUrls.GetUserInfoUrl("agent"), true);
                }
            }
            /*
            object loginData = Session["login"];
            if (null != loginData)
            {
                wxUser = loginData as WxUserInfoResult;
            }
            if (null == loginData || null == wxUser)
            {
                Response.Redirect(WechatUrls.GetUserInfoUrl("givecard"), true);
            }
            */
            int uid = wxUser.user_id;
            
            // 获取统计
            string sqlstmt = string.Format("select diamond_number from t_user_finance_account where user_id={0}", uid);
            total_count = StringUtil.ToInteger((DbFactory.Init(AppInfo.conn_yule8x_agent).GetValue(sqlstmt,"0").ToString()));
            // 获取列表
            // 交易类型(1:充值,2:返现;3:提现;4:赠送;5:领取;6:转换)
            // 转换类别(1:钻石(充值);2:泊众房卡(娱乐);3:网狐金豆(游戏))
            sqlstmt = string.Format("select create_time, transform_amount, transform_amount_type, benefactor_game_id, benefactor_game_nickname, game_mact_id, trade_type from t_finance_transaction_details where user_id={0} and trade_type in (4,5,6) order by id desc", wxUser.user_id);
            dtList = DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable(sqlstmt);
        }
        public string GetTransformType(object transform_type, object trade_type)
        {
            string text = "-";
            if (DBNull.Value == transform_type)
            {
                return text;
            }
            switch (transform_type.ToString())
            {
                case "1":
                    text = "充值";
                    break;
                case "2":
                    text = "娱乐";
                    break;
                case "3":
                    text = "游戏";
                    break;
            }
            switch (trade_type.ToString())
            {
                case "4":
                    text = "赠送";
                    break;
                case "5":
                    text = "领取";
                    break;
            }
            return text;
        }

        protected string ShortText(object value, int length, string defv = "-")
        {
            return StringUtil.Substring(value, length, defv);
        }
    }
}